class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table "users", :force => true do |t|
      t.column :login,                     :string, :limit => 40
      t.column :name,                      :string, :limit => 255
      t.column :crypted_password,          :string, :limit => 40
      t.column :salt,                      :string, :limit => 40
      t.column :created_at,                :datetime
      t.column :updated_at,                :datetime
      t.column :remember_token,            :string, :limit => 40
      t.column :remember_token_expires_at, :datetime

      # admin, editor, viewer
      t.column :permission, :string, :limit => 40, :null => false, :default => 'viewer'

      t.column :team_id, :integer, :null => true
      t.column :display_order, :integer, :null => false
    end

    add_index :users, :login, :unique => true
    add_index :users, :name, :unique => true
    add_index :users, :display_order

    admin = User.new(:login => 'administrator',
                     :name  => '管理者',
                     :password => 'administrator',
                     :password_confirmation => 'administrator',
                     :permission => 'admin',
                     :display_order => 1)
    admin.save!

  end

  def self.down
    drop_table "users"
  end
end
